﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【功能权限】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto功能权限
    /// </summary>
    public abstract class AutoRegulatorPermissionMapping : BaseMapping<RegulatorPermission, RegulatorPermissionModel, RegulatorPermissionFilterModel>
    {
        public AutoRegulatorPermissionMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override RegulatorPermissionModel Entity2Model(RegulatorPermission entity)
        {
            RegulatorPermissionModel model = new RegulatorPermissionModel();

            model.RegulatorPermissionID = entity.RegulatorPermissionID;
            model.RegulatorID = entity.RegulatorID;
            model.PermissionID = entity.PermissionID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override RegulatorPermission Model2Entity(RegulatorPermissionModel model)
        {
            RegulatorPermission entity = new RegulatorPermission();

            entity.RegulatorPermissionID = model.RegulatorPermissionID;
            entity.RegulatorID = model.RegulatorID;
            entity.PermissionID = model.PermissionID;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<RegulatorPermission> FilterModel2Where(RegulatorPermissionFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._RegulatorPermissionID.HasValue)
            {
                where = where.And(x => x.RegulatorPermissionID == filterModel._RegulatorPermissionID.Value);
            }
            if (filterModel._RegulatorPermissionIDs.IsNotEmpty() && filterModel._RegulatorPermissionIDs.Count > 0)
            {
                where = where.And(x => filterModel._RegulatorPermissionIDs.Contains(x.RegulatorPermissionID));
            }
            if (filterModel._NotRegulatorPermissionIDs.IsNotEmpty() && filterModel._NotRegulatorPermissionIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRegulatorPermissionIDs.Contains(x.RegulatorPermissionID));
            }

            //监管部门
            if (filterModel._RegulatorID.HasValue)
            {
                where = where.And(x => x.RegulatorID == filterModel._RegulatorID.Value);
            }
            if (filterModel._RegulatorIDs.IsNotEmpty() && filterModel._RegulatorIDs.Count > 0)
            {
                where = where.And(x => filterModel._RegulatorIDs.Contains(x.RegulatorID));
            }
            if (filterModel._NotRegulatorIDs.IsNotEmpty() && filterModel._NotRegulatorIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRegulatorIDs.Contains(x.RegulatorID));
            }

            //权限
            if (filterModel._PermissionID.HasValue)
            {
                where = where.And(x => x.PermissionID == filterModel._PermissionID.Value);
            }
            if (filterModel._PermissionIDs.IsNotEmpty() && filterModel._PermissionIDs.Count > 0)
            {
                where = where.And(x => filterModel._PermissionIDs.Contains(x.PermissionID));
            }
            if (filterModel._NotPermissionIDs.IsNotEmpty() && filterModel._NotPermissionIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotPermissionIDs.Contains(x.PermissionID));
            }

            return where;
        }
        #endregion
    }
}

